use util;

include "include/spellrestrictions";
include "include/client";
include "include/dotempmods";

program cast_poly( parms )

	local circle := 7;
	local caster;

	if (parms[1] = "#MOB")
		CastToad(parms[2],parms[3]);
		return;
	else
		caster := parms;
		if (!can_cast(caster, circle))
        		return;
		endif
	endif

	local origform := caster.graphic;
	local magery := cint(GetSkill(caster, SKILLID_MAGERY));
	local Critgroup;
	local thecreature;

	if (magery < 70)
		Critgroup := RandomInt(1);
	elseif (magery < 80)
		Critgroup := RandomInt(1)+1;
	elseif (magery < 90)
		Critgroup := RandomInt(1)+2;
	else
		Critgroup := 3;
	endif
	
	local critter := RandomInt(8);
	local newcolor := 1401+(critgroup*10)+critter;

	local evalint := GetSkill(caster, SKILLID_EVALINT);
	local med := GetSkill(caster, SKILLID_MEDITATION);

	local mod_amount := (critgroup*3)+critter;
	if ( (magery+med+evalint) > (80 * 3) ) 
		mod_amount := mod_amount * 2;
	endif

	local duration := GetModDuration( magery )*4;

	DoTempMod(caster, "poly", mod_amount, duration);

	DoPersistedMod(caster, "color", newcolor, caster.color, duration);

//	if (CanMod(caster, "graphic"))
//		DoPersistedMod(cast_on, "graphic", crittergraphic, caster.trueojtype, duration);
//	endif

endprogram

function CastToad(caster,cast_on)

	local circle := 7;

	if (Reflected(cast_on))
		cast_on := caster;
		if (GetObjProperty( caster, "mr") = "1")
			EraseObjProperty(caster, "mr");
			SendSysMessage(caster, "Your magic reflect spell saved you!");
			return;
		endif
	endif

	PlayObjectCenteredEffect( cast_on, FX_SMOKE, 7, 7);
	// PlayStationaryEffect( cast_on.x, cast_on.y, cast_on.z, FX_SMOKE, 0xA, 0xA );
	PlaySoundEffect( cast_on , SFX_SPELL_MANA_VAMPIRE );

	local magery := GetSkill(caster, SKILLID_MAGERY);
	local mod_amount := Resisted(circle,caster,cast_on,GetModAmount( magery ) );
	local duration := cint(GetModDuration( magery )/3);

	DoTempMod(cast_on, "cpoly", 0 - mod_amount, duration);
	DoPersistedMod(cast_on, "color", 1425, cast_on.color, duration);
	DoPersistedMod(cast_on, "graphic", 0x51, cast_on.graphic, duration);

endfunction
